﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.Company
{
    public partial class CompanyNoticeAdd : System.Web.UI.Page
    {
        private string id = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Request.QueryString["id"] + "";
            if (!Page.IsPostBack)
            {
                LoadContent();
            }
        }

        #region 加载内容
        private void LoadContent()
        {
            //判断该公司是否为该用户的
            Users uinfo = UserBase.GetCurrentUser();
            CompanysHelper chelper = new CompanysHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "ID", id);
            c.Add(CriteriaType.Equals, "OwnerUserID", uinfo.ID);
            c.Add(CriteriaType.Equals, "Flag", 0);
            List<Companys> clist = chelper.QueryCompanysBySearch(c, null);
            if (clist != null && clist.Count > 0)
            {
                string companyname = clist[0].CompanyName;
                string notice = clist[0].Notice;
                litCompanyName.Text = companyname;
                txtNotice.Text = notice;
            }
            else
            {
                Tools.AlertAndRedirect("该小组不存在或没有权限进行更改", "CompanyList.aspx");
                return;
            }
        }
        #endregion

        #region 提交
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string notice = txtNotice.Text.Trim();

            Companys cinfo = new Companys();
            CompanysHelper chelper = new CompanysHelper();
            cinfo = chelper.GetCompanys(id);
            cinfo.Notice = notice;
            chelper.EditCompanys(cinfo);

            Tools.AlertAndRedirect("修改小组公告成功", "CompanyList.aspx");
            return;
        }
        #endregion

        #region 返回
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("CompanyList.aspx");
        }
        #endregion
    }
}